﻿using Enum;
using MediatR;
using Practice.Common.Domains;
using Practice.Common.Dto;
using Practice.Common.Infrastructure.Interfaces;

namespace Practice.API.Application.Commands.UserW
{
    public class UserDelHandler:IRequestHandler<UserDelCommand,Result>
    {
        public readonly IBaseRepository<Users> UsersRepository;

        public UserDelHandler(IBaseRepository<Users> usersRepository)
        {
            UsersRepository = usersRepository;
        }

        public async Task<Result> Handle(UserDelCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonEnumCode.Success };
            try
            {
                var res = UsersRepository.GetAll().Where(x => x.UserId == request.userid).FirstOrDefault();
                if (res != null)
                {
                    res.UserStatus = true;
                    UsersRepository.Update(res);
                    result.Code = (int)CommonEnumCode.Success;
                }
                return result;

            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
